package com.dong.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.dong.exceptions.ExceptionUtil;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @RequestMapping(value = "/findOrderByUserId/{id}")
    @SentinelResource(value = "findOrderByUserId",
            fallback = "fallback",fallbackClass = ExceptionUtil.class,
            blockHandler = "handleException",blockHandlerClass = ExceptionUtil.class
    )
    public R  findOrderByUserId(@PathVariable("id") Integer id) {
        //ribbon实现
        String url = "http://mall-order/order/findOrderByUserId/"+id;
        //R result = restTemplate.getForObject(url,R.class);

        if(id==4){
            throw new IllegalArgumentException("非法参数异常");
        }

        return R.ok(url);
    }
}
